﻿using Microsoft.AspNetCore.Mvc;
using RxxAdmin.Common;
using RxxAdmin.Model.Entity;
using RxxAdmin.Model.Logs;
using RxxAdmin.Model.ViewModels;
using RxxAdmin.Model;
using RxxAdmin.IServices;

namespace RxxAdmin.Api.Controllers.log;

public class LoginLogController : BaseApiController
{
    private readonly ILoginLogService _loginLogService;

    public LoginLogController(ILoginLogService loginLogService)
    {
        _loginLogService = loginLogService;
    }

    [HttpPost]
    [OperLog("获取全部登录记录", OperEnum.Select)]
    public async Task<MessageModel<PageModel<LoginLog>>> PageList(LoginLogPageIn input)
    {
        if (string.IsNullOrEmpty(input.LoginName) || string.IsNullOrWhiteSpace(input.LoginName))
        {
            input.LoginName = "";
        }
        var loginLogs = await _loginLogService.QueryPageSplit(
                    a => a.LoginUser != null && a.LoginUser.Contains(input.LoginName),
                    input.DateTimeStart.ToLocalTime(),
                    input.DateTimeEnd.ToLocalTime(),
                    input.PageNum,
                    input.PageSize,
                    " Id desc ");
        return Success(loginLogs);
    }
}
